var domain = 'https://giftcard.dingfengst.com/'

function POST(Url, params) {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: domain + "api" + Url,
			data: params,
			method: 'POST',
			dataType: 'json',
			header: {
				"token": uni.getStorageSync('token') || ''
			},
			success: (res) => {
				uni.stopPullDownRefresh()
				if (res.data.code == 401) {
					uni.clearStorageSync('token')
					uni.reLaunch({
						url: "/pages/landing"
					})
				}
				if (res.data.code == 1) {
					resolve(res.data)
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
			},
			fail(err) {
				reject(err)
			},
			complete() {}
		});
	})
}

function GET(Url, params) {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: domain + Url,
			data: params,
			method: 'GET',
			dataType: 'json',
			header: {
				"token": uni.getStorageSync('token') || ''
			},
			success: (res) => {
				uni.stopPullDownRefresh()
				if (res.data.code == 401) {
					uni.clearStorageSync('token')
					uni.reLaunch({
						url: "/pages/landing"
					})
				}
				if (res.data.code == 200) {
					resolve(res.data)
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
			},
			fail(err) {
				reject(err)
			},
			complete() {}
		});
	})
}

module.exports = {
	POST,
	GET,
	domain,
}